const { json } = require('express')
var express = require('express')
var router = express.Router()
var detal = require('../beans/detal.js')
const Result = require('../beans/result.js')
var goodsController = require('../controllers/goods')
var getid = require('../untils/datetime_util')
// 获取全部商品信息
router.get('/list', (req, res) => {
	goodsController.getgoodlist(req.query, (result) => {
		res.json(result)
	})
})
// 商品详情
router.get('/id', (req, res) => {
	var id = req.query._id
	goodsController.getdeatel(id, (result) => {
		res.json(result)
	})
})
//搜索
router.post('/search', (req, res) => {
	// console.log('router')
	goodsController.searchgoods(req.body, (result) => {
			res.json(result)
	})
})
// 按类型查找商品

router.post('/type', (req, res) => {
	// console.log('router')
	goodsController.gettypelist(req.body, (result) => {
		const qq =
			// console.log('11111')
			res.json(result)
	})
})
// 添加商品
router.post('/add', (req, res) => {
	goodsController.addgoods(req.body, (result) => {
		res.json(result)
	})
})
// 下架商品
router.post('/del', (req, res) => {
	goodsController.delgoods(req.body, (result) => {
		res.json(result)
	})
})
// 更新商品数据
router.post('/update', (req, res) => {
	goodsController.updategoods(req.body, (result) => {
		res.json(result)
	})
})
module.exports = router
